#include "DetFinAutReverse.h"

DetFinAutReverse::DetFinAutReverse()
{
}

DetFinAutReverse::~DetFinAutReverse()
{
}

NonFinAut<char> DetFinAutReverse::reverse(DetFinAut<char> &DFA)
{
	char start = DFA.getStart();
	list<char> finishList = DFA.getFinishList();
	list<Transition<char>> transitionList = DFA.getTransitionList();
	NonFinAut<char> nonFinAut;
	list<char> tempList;
	list<Transition<char>>::const_iterator i;
	tempList.push_front(start);
	nonFinAut = NonFinAut<char>(finishList, tempList);
	for(i = transitionList.begin(); i != transitionList.end(); i++)
	{
		char tempBegin = i->end;
		char tempEnd = i->begin;
		nonFinAut.addTransition(tempBegin, i->symbol, tempEnd);
	}
	return nonFinAut;
}

DetFinAut<char> DetFinAutReverse::minimalize(DetFinAut<char> &DFA)
{
	toDetFinAut convert; 
	NonFinAut<char> tempNonFinAut = reverse(DFA);
	DetFinAut<char> tempDetFinAut = convert.convertToDetFinAut(tempNonFinAut);
	tempNonFinAut = reverse(tempDetFinAut);
	tempDetFinAut = convert.convertToDetFinAut(tempNonFinAut);
	return tempDetFinAut;
}